""" 企业微信的启动，关闭，重启 """
from appium import webdriver

from app_practice.app_wework_po.frame.base_page import BasePage
from app_practice.app_wework_po.page.main_page import MainPage
from app_practice.app_wework_po.utils.log_util import logger


class WeWorkApp(BasePage):

    def start(self):
        """启动"""
        # 定义json串
        # 复用driver
        if self.driver == None:
            logger.info("driver == None，创建driver")
            caps = {}
            caps["deviceName"] = "hogwarts"
            caps["platformName"] = "Android"
            caps["platformVersion"] = "6.0"
            caps["appPackage"] = "com.tencent.wework"
            caps["appActivity"] = ".launch.LaunchSplashActivity"
            # 防清缓存
            caps["noReset"] = "true"
            # caps["dontStopAppOnReset"] = "true"
            # 最重要！！ 完成客户端向appium 服务端发起请求，向4723这个端口的服务发起一个http 请求，然后创建一个 session 对象
            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
            # 设置隐式等待
            self.driver.implicitly_wait(self._IMPLICIT_WAIT)
        else:
            logger.info("driver 不为None，复用driver")
            # 帮我们启动应用，启动desire caps 设置的应用
            self.driver.launch_app()
            # self.driver.start_activity("com.tencent.wework", ".launch.LaunchSplashActivity")
        return self

    def restart(self):
        """重启"""
        pass

    def close(self):
        """关闭应用"""
        pass

    def goto_main(self):
        return MainPage(self.driver)